package com.cdn.allmobilestore.adapter;

import java.util.ArrayList;
import java.util.List;

import com.cdn.allmobilestore.ulti.ImageLoader;
import com.cdn.allmobilestore.ulti.ImageLoader2;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class GalleryImageAdapter extends BaseAdapter {

	private Activity context;
	private static ImageView imageView;
	private ArrayList<String> imageLinks;
	private static ViewHolder holder;
	private ImageLoader2 imageLoader;

	public GalleryImageAdapter(Activity context, ArrayList<String> imageLinks) {
		this.context = context;
		this.imageLinks = imageLinks;
		this.imageLoader = new ImageLoader2(context);
	}

	@Override
	public int getCount() {
		return imageLinks.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {

			holder = new ViewHolder();

			imageView = new ImageView(this.context);

			imageView.setPadding(3, 3, 3, 3);

			convertView = imageView;

			holder.imageView = imageView;

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();
		}

		imageLoader.DisplayImage(imageLinks.get(position), holder.imageView);
		holder.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
		holder.imageView.setLayoutParams(new Gallery.LayoutParams(400, 400));

		return imageView;
	}

	private static class ViewHolder {
		ImageView imageView;
	}

}
